package com.hzncc.flowable_diboot.contract.delegate;

import com.hzncc.flowable_diboot.contract.service.ContractAuditService;
import com.hzncc.flowable_diboot.contract.service.impl.OaInterfaceService;
import lombok.extern.log4j.Log4j2;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * @Description :
 * @Date : 2024/7/22
 * @Author : ChenJin
 * @Version : v1.0.0
 **/
@Log4j2
@Service
public class OaDelegate implements JavaDelegate {

    @Resource
    private ContractAuditService contractAuditService;
    @Resource
    private OaInterfaceService oaInterfaceService;

    @Override
    public void execute(DelegateExecution delegateExecution) {
        //String instanceId = delegateExecution.getProcessInstanceId();
        //LambdaQueryWrapper<ContractAudit> queryWrapper = new LambdaQueryWrapper<>();
        //queryWrapper.eq(ContractAudit::getInstanceId, instanceId).eq(ContractAudit::isDeleted, 0);
        //ContractAudit contractAudit = contractAuditService.getSingleEntity(queryWrapper);
        // 请求封装
        //MultiValueMap<String, Object> requestParam = oaInterfaceService.getRequestParam(contractAudit.getId());
        //// OA推送
        //String url = "/api/km-review/kmReviewRestService/addReview";
        //String msg;
        //String res = OAStatusEnum.SUCCESS.getName();
        //try {
        //    msg = oaInterfaceService.accessOaInterface(url, requestParam);
        //    if(S.equals(msg,"user is not exist")){
        //        res = OAStatusEnum.FAIL.getName();
        //        msg = "推送失败，"+msg;
        //    }
        //} catch (Exception e) {
        //    msg = "推送失败，系统错误";
        //    log.error("OA推送失败",e);
        //}
        //// 推送完成后，获取响应结果，变更合同审批状态
        //contractAudit.setContractStatus(ContractAuditStatusEnum.OA_PROCESSING.getCode())
        //        .setOaStatus(res).setOaMsg(msg);
        //contractAuditService.updateEntity(contractAudit);
    }
}
